<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>
        <%= title %>
    </title>
    <!-- Bootstrap Core CSS -->
    <link href="index/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <!-- MetisMenu CSS -->
    <link href="index/vendor/metisMenu/metisMenu.min.css" rel="stylesheet">
    <!-- Custom CSS -->
    <link href="index/dist/css/sb-admin-2.css" rel="stylesheet">
    <!-- Custom Fonts -->
    <link href="index/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
    <div class="container">
        <div class="row">
            <div class="col-md-4 col-md-offset-4">
                <div class="login-panel panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">Please Sign In</h3>
                    </div>
                    <div class="panel-body">
                        <form role="form" method="post" id="login">
                            <fieldset>
                                <!-- 隐藏字段提交 -->
                                <input type="hidden" id="redirect" name="redirect">

                                <div class="form-group">
                                    <input class="form-control" placeholder="Username" id="username" name="username" type="text" autofocus>
                                </div>
                                <div class="form-group">
                                    <input class="form-control" placeholder="Password" id="password" name="password" type="password" value="">
                                </div>
                                <div class="checkbox">
                                    <label>
                                        <input name="remember" type="checkbox" value="Remember Me">Remember Me
                                    </label>
                                </div>
                                <!-- Change this to a button or input when using this as a form -->
                                <a href="#" class="btn btn-lg btn-success btn-block" onclick="submit()">Login</a>
                            </fieldset>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 生成Token -->
    <script>
        /** 
         * 解析地址栏参数
         * name:"redirect"
         **/
        function GetQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }

        /** 
         * 发送请求
         **/
        function submit() {
            //添加请求参数
            var redirect = GetQueryString("redirect");
            $("#redirect").val(redirect);
            //form提交
            $("#login").submit()
                // $.ajax({
                //     type: "post",
                //     url: "/api/authenticate",
                //     data: {
                //         username: $("#username").val(),
                //         password: $("#password").val()
                //     },
                //     dataType: "json",
                //     success: function (data) {
                //         //添加请求参数
                //         var redirect = GetQueryString("redirect");
                //         $("#redirect").val(redirect);
                //         $("#token").val(token);
                //         //将Token写入sessionStorage中
                //         var token = data.token;
                //         sessionStorage.setItem("key", "value");
                //         //form提交
                //         $("#login").submit()

            //     },
            //     error: function (data) {
            //         alert(data)
            //     }
            // })
        }
    </script>